define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'vip_user/index' + location.search,
                    // add_url: 'vip_user/add',
                    // edit_url: 'vip_user/edit',
                    // del_url: 'vip_user/del',
                    // multi_url: 'vip_user/multi',
                    // import_url: 'vip_user/import',
                    table: 'vipuser_list',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'vipUser',
                sortName: 'gatherTime',
                // templateView: false,
                // clickToSelect: false,
                // search: false,
                // showColumns: false,
                // showToggle: false,
                // showExport: false,
                // showSearch: false,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        
                        {
                            field: 'vipUser', title: __('Userid'), operate: false
                        },
                        {
                            field: 'nickname', title: __('Nickname'), operate: false
                        },
                        {
                            field: 'gender', title: __('Gender'), formatter: function (value) {
                                if (value == 0)
                                    return "未知";
                                else if (value == 1)
                                    return "男";
                                else if (value == 2)
                                    return "女";
                                else if (value == 3)
                                    return "中性";
                            }
                        },
                        {
                            field: 'grade', title: __('Usergrade')
                        },
                        {
                            field: 'language', title: __('Language')
                        },
                        {
                            field: 'region', title: __('Region')
                        },
                        
                        //{    field: 'relatedUserNum', title: __('UserNum related')},
                        
                        {
                            field: 'gatherTime',
                            title: __('Spidertime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'robotUser', title: __('Spiderrobot'), operate: 'LIKE'
                        },
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
